www.gusucode.com > 6KBBS ASP版 V7.1 > 6KBBS ASP版 V7.1\code\bbs\inc\ubbcode.asp

    <%
dim tt1,tt2
tt1="<font style='font-size:9pt;line-height:15pt'><hr color=#CDCFCE size=1><font color=#808080>"
tt2="</font><hr color=#CDCFCE size=1>"
function html_encode(byval str)
    if isnull(str) then
	 html_encode=""
	else
	'str=replace(str,"&","&amp;")
	'str=replace(str,chr(32),"&nbsp;")
	'str=replace(str,chr(39),"&#39;")
	'str=replace(str,chr(36),"&#36;")
	'str=replace(str,chr(34),"&quot;")
	'str=replace(str,"<","&lt;")
	'str=replace(str,">","&gt;")
	str = Replace(str, chr(13), "")
    str = Replace(str, chr(10) &chr(10), "</p><p> ")
    html_encode = Replace(str, chr(10), "<br> ")
	end if
end function
function ubb_base(byval str)
	dim regEx
	set regEx=new regExp
	regEx.IgnoreCase=true
	regEx.Global=true
	if isnull(str) or str="" then
		ubb_base=""
		exit function
	end if
	str=me.html_encode(str)
	regEx.pattern="((script)|(javascript:)|(jscript:)|(object)|(js:)|(location.)|(vbscript:)|(vbs:)|(\.value)|(about:)|(file:)|(document.cookie)|(on(mouse|exit|error|click|key|load)))"
	str=regEx.replace(str,"<I>$1</I>")
	regEx.Pattern="((ifr|fr)ame)"
	str=regEx.Replace(str,"<I>$2ame</I>")
	
	regEx.pattern="\[UPLOAD=(gif|jpg|jpeg|bmp|png)\](.[^\[]*)(gif|jpg|jpeg|bmp)\[\/UPLOAD\]"
	str=regEx.replace(str,"<br><IMG SRC=""images/upfiletype/$1.gif"" border=0> 此主题相关图片如下:<br><SPAN style='CURSOR: hand'><IMG SRC=""upload/$2$1"" border=0 alt=按此在新窗口浏览图片 onload=""javascript:if(this.width>screen.width-500)this.width=screen.width-500"" onclick=""window.open(this.src,null,'')""></span>")
	regEx.pattern="\[IMG\](http|https|ftp):\/\/(.[^\[]*)\[\/IMG\]"
	str=regEx.replace(str,"<img src=$1://$2 border=0 style='cursor:hand' onload=""javascript:if(this.width>screen.width-333)this.width=screen.width-333"" onclick=""window.open(this.src,null,'')"">")
	regEx.pattern="(\[sound\])(.[^\[]*)(\[\/sound\])" 
	str=regEx.Replace(str,"<a href=""$2"" target=_blank><IMG SRC=images/mid.gif border=0 alt='背景音乐'></a><bgsound src=""$2"" loop=""-1"">")
	regEx.pattern="\[em([0-9]{1,2})]"
	str=regEx.replace(str,"<img src=images/emote/em$1.gif>")
	regEx.pattern="\[((/?b)|(/?u)|(/?sub)|(/?sup))\]"
	str=regEx.replace(str,"<$1>")
	regEx.pattern="\[i\]((.|\n)+?)\[/i\]"
	str=regEx.replace(str,"<i>$1</i>")
	regEx.pattern="\[color=((#.{6})|.{3,6})\]((.|\n)*?)\[/color\]"
	str=regEx.replace(str,"<font color=#$1>$3</font>")
	regEx.pattern="\[url=(.{5,}?)\](.+?)\[/url\]"
	str=regEx.replace(str,"<a href=""$1"" target='_blank'>$2</a>")
	regEx.Pattern="(\[url\])(http:\/\/\S+?)(\[\/url\])"
	str=regEx.replace(str,"<a href=""$2"" target='_blank'>$2</a>")
	regEx.pattern="\[EMAIL\]([^\s@]+@[^\.]+\..+?)\[\/EMAIL\]"
	str=regEx.replace(str,"<a href=""mailto:$1"" target='_blank'>$1</a>")
	regEx.pattern="\[EMAIL=([^\s@]+@[^\.]+?\..+?)\](.+?)\[\/EMAIL\]"
	str=regEx.replace(str,"<a href=""mailto:$1"" target='_blank'>$2</a>")
	regEx.Pattern="\[MP=*([0-9]*),*([0-9]*)\](.[^\[]*)\[\/MP]"
	str=regEx.Replace(str,"<br><b>此主题相关媒体如下:<a href=""$3"" TARGET=_blank>(点这里下载)</a></b><br><object align=middle classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 class=OBJECT id=MediaPlayer width=$1 height=$2 >" & vbcrlf & "<PARAM NAME=AUTOSTART VALUE=0><param name=ShowStatusBar value=-1>" & vbcrlf & "<param name=Filename value=$3>" & vbcrlf & "<embed type=application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701 flename=mp src=$3 width=$1 height=$2>" & vbcrlf & "</embed>" & vbcrlf & "</object>")
	regEx.Pattern="\[RM=*([0-9]*),*([0-9]*)\](.[^\[]*)\[\/RM]"
	str=regEx.Replace(str,"<b>此主题相关媒体如下:<a href=""$3"" TARGET=_blank>(点这里下载)</a></b><br><OBJECT classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA class=OBJECT id=RAOCX width=$1 height=$2>" & vbcrlf & "<PARAM NAME=SRC VALUE=$3>" & vbcrlf & "<PARAM NAME=CONSOLE VALUE=Clip1>" & vbcrlf & "<PARAM NAME=CONTROLS VALUE=imagewindow>" & vbcrlf & "<PARAM NAME=AUTOSTART VALUE=false>" & vbcrlf & "</OBJECT>" & vbcrlf & "<br>" & vbcrlf & "<OBJECT classid=CLSID:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA height=32 id=video2 width=$1>" & vbcrlf & "<PARAM NAME=SRC VALUE=$3>" & vbcrlf & "<PARAM NAME=AUTOSTART VALUE=0>" & vbcrlf & "<PARAM NAME=CONTROLS VALUE=controlpanel>" & vbcrlf & "<PARAM NAME=CONSOLE VALUE=Clip1>" & vbcrlf & "</OBJECT>")
	regEx.Pattern="\[DIR=*([0-9]*),*([0-9]*)\](.[^\[]*)\[\/DIR]"
	str=regEx.Replace(str,"<b>此主题相关的FLASH文件如下:</b><br>$3")
	regEx.Pattern="\[Ra\](.[^\[]*)\[\/Ra]"
	str=regEx.replace(str,"<b>此主题相关的 RealPlayer 音乐如下:[ <a href=$1>下载</a> ]</b><br><object classid=clsid:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA class=OBJECT id=RAOCX width=280 height=70><param name=_ExtentX value=7938><param name=_ExtentY value=2646><param name=AUTOSTART value=0><param name=SHUFFLE value=0><param name=PREFETCH value=0><param name=NOLABELS value=0><param name=LOOP value=0><param name=NUMLOOP value=0><param name=CENTER value=0><param name=MAINTAINASPECT value=0><param name=BACKGROUNDCOLOR value=#000000><PARAM NAME=SRC VALUE=$1></object>")
	
	
	regEx.pattern="\[align=(center|left|right)\](.*)\[\/align\]"
	str=regEx.replace(str,"<div align=$1>$2</div>")
	regEx.pattern="\[right\]((.|\n)+?)\[/right\]"
	str=regEx.replace(str,"<div align=right>$1<//div>")
	regEx.pattern="(\[quote\])((.|\n)+?)(\[\/quote\])"
	str=regEx.replace(str,"<FIELDSET  style='PADDING-RIGHT: 2px; PADDING-LEFT: 2px; PADDING-BOTTOM: 2px;  PADDING-TOP: 2px;'><LEGEND>引用回复</LEGEND><BR>$2<BR></FIELDSET>")
	regEx.pattern="\[SIZE=([1-4])\]((.|\n)+?)\[\/SIZE\]"
	str=regEx.replace(str,"<font size=$1>$2</font>")
	regEx.Pattern="(\[UPLOAD=(.[^\[]*)\])(.[^\[]*)(\[\/UPLOAD\])"
	str=regEx.Replace(str,"<IMG SRC=""images/upfiletype/$2.gif"" border=0> <a target=_blank href=upload/$3>点击浏览该文件</a>")
	regEx.Pattern="\[fly\](.+?)\[\/fly\]"
	str=regEx.replace(str,"<marquee width=90% behavior=alternate scrollamount=3>$1</marquee>")
	regEx.Pattern="\[move\](.+?)\[\/move\]"
	str=regEx.replace(str,"<MARQUEE scrollamount=3>$1</marquee>")	
	regEx.Pattern="\[SHADOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)\](.[^\[]*)\[\/SHADOW]"
	str=regEx.replace(str,"<table width=$1 ><tr><td style=""filter:shadow(color=$2, stregExngth=$3)"">$4</td></tr></table>")
	regEx.Pattern="\[light\](.[^\[]*)\[\/light]"
	str=regEx.replace(str,"<span style=""behavior:url(inc/font.htc)"">$1</span>")
	
	regEx.Pattern = "^((http|https|ftp|rtsp|mms):(\/\/|\\\\)[A-Za-z0-9\./=\?%\-&_~`@':;#+!]+)"
	str=regEx.Replace(str,"<img align=absmiddle src=images/url.gif border=0><a target=_blank href=$1>$1</a>")
	regEx.Pattern = "((http|https|ftp|rtsp|mms):(\/\/|\\\\)[A-Za-z0-9\./=\?%\-&_~`@':;#+!]+)$"
	str=regEx.Replace(str,"<img align=absmiddle src=images/url.gif border=0><a target=_blank href=$1>$1</a>")
	regEx.Pattern="([^>=""])((http|https|ftp|rtsp|mms):(\/\/|\\\\)[A-Za-z0-9\./=\?%\-&_~`@':;+!]+)"
	str=regEx.Replace(str,"$1<img align=absmiddle src=images/url.gif border=0><a target=_blank href=$2>$2</a>")
	
	
	
	regEx.Pattern="(^.*)(\[smark=*([0-9]*)\])(.[^\[]*)(\[\/s\])(.*)"
	dim needmark,usermark
	needmark=regEx.Replace(str,"$3")
	if IsNumeric(needmark) then needmark=int(needmark) else needmark=0
	if isnull(lguserid) or lguserid="" then
	usermark=0
	else
	usermark=conn.execute("select top 1 mark from [user] where userid="&lguserid&"")("mark")
	end if
	if lguserid=topicuserid or usermark>=needmark then
	str=regEx.Replace(str,"$1"&tt1&"此内容需要积分 <b>"&needmark&"</b> 以上的用户以及作者才能浏览:</font><BR>$4"&tt2&"$6")
	else
	str=regEx.Replace(str,"$1"&tt1&"此内容需要积分 <b>"&needmark&"</b> 以上的用户以及作者才能浏览:</font><BR>"&tt2&"$6")
	end if
	
	
	regEx.Pattern="(^.*)(\[slogin\])(.[^\[]*)(\[\/s\])(.*)"
	if  isnull(lguserid) or lguserid="" then
	str=regEx.Replace(str,"$1"&tt1&"此帖内容<b>必须<a href=login.asp>登陆</a></b>后才能浏览:</font><BR>"&tt2&"$5")
	else
	str=regEx.Replace(str,"$1"&tt1&"此帖内容<b>必须登陆</b>后才能浏览:</font><BR>$3"&tt2&"$5")
	end if
	
	
	regEx.Pattern="(^.*)(\[showdate=(.[^\[]*)\])(.[^\[]*)(\[\/s\])(.*)"
	dim showdate
	showdate=regEx.replace(str,"$3")
	if isdate(showdate) then 
	showdate=datediff("d",cdate(showdate),cdate(now()))
	else 
	showdate=-1
	end if
	if int(showdate)>=0 or lguserid=topicuserid then
	str=regEx.Replace(str,"$1"&tt1&"此内容只有 <b>$3</b> 这天以后才能浏览:</font><BR>$4"&tt2&"$6")
	else
	str=regEx.Replace(str,"$1"&tt1&"此内容只有 <b>$3</b> 这天以后才能浏览:</font><BR>"&tt2&"$6")
	end if
	
	
	regEx.Pattern="(^.*)(\[showtograde=*([0-9]*)\])(.[^\[]*)(\[\/s\])(.*)"
	dim needgrade,usergrade
	needgrade=regEx.Replace(str,"$3")
	if IsNumeric(needgrade) then
	needgrade=int(needgrade) 
	else
	needgrade=0
	end if
	if isnull(lguserid) or lguserid="" then
	usergrade=0
	else
	usergrade=conn.execute("select top 1 grade from [user] where userid="&lguserid&"")("grade")
	end if
	
	if lguserid=topicuserid or usergrade>=needgrade then
	str=regEx.Replace(str,"$1"&tt1&"此内容需要等级为 <b>"&needgrade&"</b> 或更高的等级以及作者才能浏览:</font><BR>$4"&tt2&"$6")
	else
	str=regEx.Replace(str,"$1"&tt1&"此内容需要等级为 <b>"&needgrade&"</b> 或更高的等级以及作者才能浏览:</font><BR>"&tt2&"$6")
	end if
	
	
	regEx.Pattern="(^.*)(\[showtoname=(.[^\[]*)\])(.[^\[]*)(\[\/s\])(.*)"
	dim showtoname,cansee,n
	showtoname=regEx.replace(str,"$3")
	showtoname=split(showtoname,",")
	cansee=false
	for n=0 to ubound(showtoname)
	if lcase(lgname)=lcase(showtoname(n)) then:cansee=true:exit for
	next
	
	if cansee=true or lguserid=topicuserid then
	str=regEx.Replace(str,"$1"&tt1&"此内容只有作者和 <b>$3</b> 能浏览:</font><BR>$4"&tt2&"$6")
	else
	str=regEx.Replace(str,"$1"&tt1&"此内容只有作者和 <b>$3</b> 能浏览:</font><BR>"&tt2&"$6")
	end if
	
	regEx.Pattern="(^.*)(\[showtoreply\])(.+?)(\[\/s\])(.*)"
	dim canread,ubbrs
	canread=false
	if isnull(lguserid) or lguserid="" then
	canread=false
	else
	set ubbrs=conn.execute("select top 1 id from bbs"&totable&" where bid="&id&" and userid="&lguserid&"")
	if not ubbrs.eof or lguserid=topicuserid then canread=true
	set ubbrs=nothing
	end if
	if canread=true then
	str=regEx.Replace(str,"$1"&tt1&"此内容只有作者和已经回复此帖的浏览者能浏览:</font><BR>$3"&tt2&"$5")
	else
	str=regEx.Replace(str,"$1"&tt1&"此内容只有作者和已经回复此帖的浏览者能浏览:</font><BR>"&tt2&"$5")
	end if
	
	ubb_base=str
	set regEx=nothing
end function

function ubbhtml(byval str)
	dim ary_string,i,n,n_pos
	ary_string=split(str,"[code]")
	n=ubound(ary_string)
	if n<1 then
		ubbhtml=me.ubb_base(str)
		exit function
	end if
	ary_string(0)=me.ubb_base(ary_string(0))
	for i=1 to n
		n_pos=instr(ary_string(i),"[/code]")
		if n_pos>0 then
			ary_string(i)="<form><textarea style='font-family: 宋体; font-size: 9pt;width:90%' name='dbg' rows='10'>" & text_encode(left(ary_string(i),n_pos-1)) & "</textarea><p style='margin:5px'><input type='button' class='button' value='运行此代码' style='width:80px' onclick='runit(this.form.dbg)'> <input type='button' class='button' value='复制到剪贴板' style='width:90px' onclick='copyit(this.form.dbg)'> <input type='button' class='button' value='代码另存为' style='width:80px' onclick='saveAs(this.form.dbg)'></p> </form>" & ubb_base(right(ary_string(i),len(ary_string(i))-n_pos-6))
		else
			ary_string(i)="[code]" & me.ubb_base(ary_string(i))
		end if
	next
	ubbhtml=join(ary_string,"")
end function

function ubb(byval str)
		if isnull(str) or str="" then
			ubb=""
			exit function
		end if
	str=replace(str,"login.asp","<span>login.asp</span>")
	str=replace(str,"adminbd","<span>adminbd</span>")
	dim ary_string,i,n,n_pos
	ubb=me.ubbhtml(str)
end function

function text_encode(byval str)
	if isnull(str) then
		text_encode=""
	else
		'str=replace(str,"&","&amp;")
		str=replace(str,"<","&lt;")
		text_encode=replace(str,">","&gt;")
	end if
end function
%><script>
function copyit(obj){
	obj.select();
	js=obj.createTextRange();
	js.execCommand("Copy");
}
function saveAs(obj){
	var winname=window.open('','test','top=10000');
	winname.document.open("text/html", "replace");
	winname.document.write(obj.value);
	winname.document.execCommand('saveas','','code.html');
	winname.close();
}
function runit(obj)
{
var winname=window.open("","test","");
winname.document.open("text/html", "replace");
winname.document.write(obj.value);
winname.document.close();
}
</script>